package com.longteng.lesson2.dao.impl;

import com.longteng.lesson2.dao.IUserDao;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Created by li
 * DATE : 2018/11/25 0025
 * TIME : 22:58
 * PROJECT : java-lesson
 * PACKAGE : com.longteng.lesson
 *
 * @author <a href="mailto:55324936@qq.com">li</a>
 */
@Repository("newUserDao")
public class NewUserDao implements IUserDao {
    NewUserDao(){}

    private String address;
    private String city;

    NewUserDao(String address){
        this.address=address;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getCity() {
        return city;
    }

    @Override
    public void addUserName(String userName) {
        System.out.println("dao的add方法传入进来的参数:"+userName);
        System.out.println("输出数据库的内容");
    }
    List<Map<String,String>> mapList=new ArrayList<>();
    //初始化的方法
    public void initUser(){
        Map<String,String> map=new HashMap<>();
        map.put("userName","a");
        map.put("city",this.getCity());
        map.put("address",this.getAddress());
        mapList.add(map);
        Map<String,String> map2=new HashMap<>();
        map2.put("userName","b");
        map2.put("city",this.getCity());
        map2.put("address",this.getAddress());
        mapList.add(map2);
    }

    @Override
    public Map<String, String> getUserByName(String userName) {
       List<Map<String,String>> list = mapList.stream().
               filter(m-> m.get("userName").equalsIgnoreCase(userName))
                .collect(Collectors.toList());
       return list.get(0);
    }
}
